-- 辣椒炸弹类
local Plant = require("app.mode.Plant")
local AniHelper = require("app.utils.AnimateHelper")

local Jalapeno = {}
setmetatable(Jalapeno, Plant)
Jalapeno.__index = Jalapeno

function Jalapeno:runAnimate()
    if self._sprite and self._animate then
        local function finish(node, data)
            self:removeSelf()
            self._scene:removePlant(self)
        end

        local function attack(node, data)
            local sprite
            sprite, self._animate = AniHelper("plants/", self:getName() .. "_attack", 0.1, 1)
            self._sprite:setSpriteFrame(sprite:getSpriteFrame())
            self._sprite:setPositionX(cc.Director:getInstance():getVisibleSize().width / 2)
            self._sprite:runAction(cc.Sequence:create(self._animate, cc.CallFunc:create(finish), nil))
            self._scene:jalapenoExplode(self)
        end

        local animation = self._animate:getAnimation()
        animation:setDelayPerUnit(0.1)
        animation:setLoops(1)
        self._animate = cc.Animate:create(animation)
        self._sprite:runAction(cc.Sequence:create(self._animate, cc.CallFunc:create(attack), nil))
    end
end

function Jalapeno:beAttack(attack)
end

return Jalapeno
